<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ include file="/include/taglibs.jsp"%>
<head>
<title>设备列表</title>
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath() %>/styles/hx.base.css">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath() %>/styles/hx.base.css">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath() %>/styles/hx.list.css">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath() %>/styles/hx.content.css" />
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath() %>/styles/calendar-themes.css" />
<link href="<%=request.getContextPath() %>/styles/uniform/default.uni-form.css" media="screen"
	rel="stylesheet" />
<script type="text/javascript" src="<%=request.getContextPath() %>/scripts/jquery.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/scripts/hx.utils.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/scripts/hx.list.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/scripts/sortabletable.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/scripts/calendar.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/scripts/calendar-zh.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/scripts/JHashMap.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/scripts/huaxia.common.js"></script>
</head>
<style type="text/css">
body {
	background-image: url(../images/mainframe-bg.jpg);
	background-repeat: repeat-x;
	margin: 0px auto;
	padding: 0px;
	position: relative;
	text-align: center;
}
</style>

<script language="javascript">
<!--
function senfe(o,a,b,c,d){
var t=document.getElementById(o).getElementsByTagName("tr");
for(var i=0;i<t.length;i++){
t[i].style.backgroundColor=(t[i].sectionRowIndex%2==0)?a:b;
t[i].onclick=function(){
if(this.x!="1"){
this.x="1";//本来打算直接用背景色判断，FF获取到的背景是RGB值，不好判断
this.style.backgroundColor=d;
}else{
this.x="0";
this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
}
}
$(t[i]).mouseover(function(){
if(this.x!="1")this.style.backgroundColor=c;
});
$(t[i]).mouseout(function(){
if(this.x!="1")this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
});
}
}
$(document).ready(function (){
	//senfe("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景");
	senfe("t_robotlog","#e5f1f4","#f8fbfc","#ecfbd4","#bce774");
});
--></script>

<script type="text/javascript">
function search(){			
   frmList.submit();	
}
</script>

<script type="text/javascript">
<!--
function fnFam(str){
	return str.replace(/(^\,*)|(\,*$)/g, "");
}

function submitFun(){    
	var keys="";
	var keyArr=window.opener.linkMap.keySet();
	if(keyArr!=null){
		for(var i=0;i<keyArr.length;i++){
			keys=keyArr[i]+","+keys;	
		}
		keys=fnFam(keys);
 	}
 	 
 	window.opener.document.getElementById("robotIds").value=keys;
 	window.opener.document.getElementById("groupManageId").value='${queryIdGroup}';
 	
 	var form = window.opener.document.getElementById("t_groupmanage");
  	form.action="common.groupnavi.do?action=addRelRobot";
  	form.submit();
	window.close();
	
}

function  checkRow(){
	var ids=document.getElementsByName("id");
	for(var i=0;i<ids.length;i++){
		if(ids[i].checked){
			window.parent.opener.linkMap.put(ids[i].value,ids[i].value);
		}else{
			window.parent.opener.linkMap.remove(ids[i].value);
		}
	}
		
}

function checkAll(){
	list_select_all();
	checkRow();
}

function autoCheckSelected()
{
	var ids=document.getElementsByName("id");
	for(var i=0;i<ids.length;i++){
		if(window.parent.opener.linkMap.containsKey(ids[i].value)){
			ids[i].checked=true;
		}
	}
}
//-->
</script>

<div>
<div style="text-align: left; color: red"><html:errors /></div>
<form id="frmList" action="ne.robotchoosequery.do" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0"
	class="sanxuan" style="background-repeat: repeat;">
	<tbody>
		<tr>
			<td height="31" width="900px"
				style="font-size: 14px; color: white; text-align: center">&nbsp;设备查询</td>
		</tr>
		<tr>
			<td>
			<table border="0" width="95%" align="center">
				<tr align="left">
					<td><strong>顶级区域 :</strong>
					<select name="queryIdRegion" id="queryIdRegion"  style ="width:125px" onChange="doAutoSelect('regionId',this.value,'queryIdSubRegion');">
						<option value="">请选择...</option>
						<c:forEach items="${RA_ROOT_REGIONS}" var="region">
							<option value="${region.idRegion}">${region.regionName}</option>
						</c:forEach>
					</select>
					<strong>子级区域 :</strong>
					<select name="queryIdSubRegion" id="queryIdSubRegion"  style ="width:175px">
						<option value="">请选择...</option>
						<c:forEach items="${RA_SUB_REGIONS}" var="region">
							<option value="${region.idRegion}">${region.regionName}</option>
						</c:forEach>
					</select>
					<strong>设备名称 :</strong>
					<input name="queryRobotName" id="queryRobotName" value="" width="125px;">					
					</td>
					<td align="left"><img
						src="<%=request.getContextPath() %>/images/table/chaxun.gif"
						width="90" height="30" style="cursor: hand;"
						onclick="javascript:search();" /></td>
				</tr>
			</table>
			</td>
		</tr>
	</tbody>
</table>

<div class="guanli" style="float: right;">
<input name="add" type="button" class="button" value="确定"
	onclick="javascript:submitFun();"/></div>	
<table width="100%" cellpadding="4" class="liebiao" id="t_robotmanage"
	align="center">
	<thead>
		<tr>
			<td width="23" align="center"><input id="all" name="all"
				type="checkbox" onclick="checkAll();" /></td>
			<td>所属区域</td>			
			<td>设备名称</td>
			<td>IP地址</td>			
		</tr>
	</thead>
	<tbody>
		<c:forEach var='bean' items="${RA_PAGER_ITEMS}" varStatus="vs">
			<tr>
				<td class="list-value"><input id="id" name="id" type="checkbox"
					value="${bean.robotManage.idRobot}"
					onClick="checkRow();"></td>			
				<td class="list-value">
					${bean.robotManage.regionManage.regionName}</td>
				<td class="list-value">${bean.robotManage.name}</td>
				<td class="list-value">${bean.robotNetInfo.ipAddress}</td>				
			</tr>
		</c:forEach>
	</tbody>
	<tfoot>
	</tfoot>
</table>
<div class="pagenav"><jsp:include page="/include/pager.jsp"
	flush="true" /></div>
</form>
</div>
<script type="text/javascript">
var st = new SortableTable( document.getElementById("t_robotmanage"), ["None", "String","String", "String"],'#E4EEF7','white','#FF9900');

var type;
var targetId;
function doAutoSelect(typeTemp,keyValue,targetTemp) {
    
	type=typeTemp;
	targetId=targetTemp;
      var url = "<c:url value='/common.regionAutoSelect.do?keyValue="+keyValue+"&type="+type+"'/>";
     　　if (window.XMLHttpRequest) {
             　　  req = new XMLHttpRequest();
     　　}else if (window.ActiveXObject) {
             　　req = new ActiveXObject("Microsoft.XMLHTTP");
     　　}
     　 if(req){
             　req.open("GET",url, true);
             　　req.onreadystatechange = complete;
             　　req.send(null);
     　　}
 }
 function complete(){
     　　if (req.readyState == 4) {
             　　if (req.status == 200) {
	             if(type=="regionId"){
	            	  var strLink = req.responseXML.getElementsByTagName("subregion");
         	    	  var key=new Array();
         	    	  var value=new Array();
                      for(var i=0;i<strLink.length;i++){                      	                    	
                          key[i]=strLink[i].firstChild.data.split(",")[0];                                                
                          value[i]=strLink[i].firstChild.data.split(",")[1];                            
                     　　}                     
                     buildSelect(key,value,document.getElementById(targetId));   
         	     }
         	  }
     　　}
 }
function buildSelect(key,value,sel) {
     　　	sel.options.length=0;
		sel.options[sel.options.length]=new Option("请选择...","");
     　　	for(var i=0;i<key.length;i++) {     	
             　　sel.options[sel.options.length]=new Option(value[i],key[i]);
     　　	}
}
</script>